import http from '../../../http/http'
import * as url from '../../../http/api';
import el from 'element-ui/src/locale/lang/el';

const state = {
    pageSize:0,
    dishsData:[],
    dishTypeData:[],
    orderDetailData:{},
}
const actions = {
    getDishData({commit},obj){
        return new Promise((resolve,reject)=>{
            http({
                url:url.getDishData,
                method:'post',
                data:obj
            }).then(res=>{
                commit('saveDishData',res.data)
                resolve()
            })
        })     
    },
    getDishType({commit}){
            http({
                url:url.getDishType,
                method:'post',
            }).then(res=>{
                console.log(res.data,'getDishType')
                commit('saveDishType',res.data)
            })
        
    },
    searchDishName({commit},obj){
        return new Promise((resolve,reject)=>{
            http({
                url:url.searchDishName,
                method:'post',
                data:obj,
            }).then(res=>{
                if(res.data.status == 'success'){
                    commit('saveSearchData',res.data)
                    resolve('success')
                }else{
                    resolve('error')
                }
            })
        })
        
    },
    searchDishType({commit},obj){
        return new Promise((resolve,reject)=>{
            http({
                url:url.searchDishType,
                method:'post',
                data:obj,
            }).then(res=>{
                console.log(res.data,'搜索菜品类型')
                if(res.data.status == 'success'){
                    commit('saveSearchData',res.data)
                    resolve('success')
                }else{
                    resolve('error')
                } 
            })
        })
        
    },
    verifyTable({commit},obj){
        return new Promise((resolve,reject)=>{
            http({
                url:url.verifyTable,
                method:'post',
                data:obj,
            }).then(res=>{
                console.log(res.data,'查询订单')
                if(res.data.status == 'success'){
                    commit('saveOrderDetail',res.data.diningOrderMain)
                    resolve('success')
                }else{
                    resolve('error')
                }
               
                // resolve(res.data.diningOrderMain) 
            })
        })
    },
    saveOrder({commit},obj){
        return new Promise((resolve,reject)=>{
            console.log('我要西订单了',obj)
            http({
                url:url.saveOrder,
                method:'post',
                data:obj,
            }).then(res=>{
                console.log(res,'saveOrder')
                if(res.data.status == 'success'){
                    resolve('success')
                }else{
                    resolve('error')
                }
              
            })
        })
        
    },
    editOrder({commit},obj){
        return new Promise((resolve,reject)=>{
            http({
                url:url.editOrder,
                method:'post',
                data:obj,
            }).then(res=>{
                console.log(res.data)
                if(res.data.status == 'success'){
                    resolve('success')
                }else{
                    resolve('error')
                }
            })
        })   
    },
    deleteOrderDish({commit},obj){
         return new Promise((resolve,reject)=>{
            http({
                url:url.deleteOrderDish,
                method:'post',
                data:obj,
            }).then(res=>{
                if(res.data.status == 'success'){
                    resolve('success')
                }else{
                    resolve('error')
                }
            })
        })
        
    },
    addOrderDish({commit},obj){
        // return new Promise((resolve,reject)=>{

        // })
        return new Promise((resolve,reject)=>{
            http({
                url:url.addOrderDish,
                method:'post',
                data:obj,
            }).then(res=>{
                if(res.data.status == 'success'){
                    console.log(res.data)
                    resolve('success')
                }else{
                    resolve('error')
                }
            })
        })
        
    },
    beginVerify({commit},obj){
        return new Promise((resolve,reject)=>{
            http({
                url:url.beginVerify,
                method:'post',
                data:obj,
            }).then(res=>{
                console.log(res.data.Text,'beginVerify')
                resolve(res.data.Text) 
            })
        })
    }
}
const mutations = {
    saveDishData(state,data){
        state.pageSize = data.totalPage
        state.dishsData = data.listDishes
    },
    saveDishType(state,data){
        state.dishTypeData = data
    },
    saveSearchData(state,data){
        state.pageSize = data.totalPage
        state.dishsData = data.dishesList
    },
    saveOrderDetail(state,data){
        state.orderDetailData = data
    }
}
const getters = {

}
export default{
    namespaced: true,
    state,
    actions,
    mutations,
    getters,
}